# encoding=utf-8
import redis
import re
import json
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

red = redis.Redis(host='127.0.0.1', port=6379)
number = red.llen('taobao_info_new')
print(number)
list_1 = []
a = []
list_1 = red.lrange('taobao_info_new', 1,number)

sales_beast = {}
for each in list_1:
    list_2 = each.decode('utf-8')
    list_2 = list_2.replace("'", '"')
    list_3 = json.loads(list_2)
    number = list_3['month_sales']
    title = list_3['title']
    sales_beast[number] = title
for i in sales_beast:
    if int(i) >= 10000:
        a.append(i + "," + sales_beast[i])

print(a)

with open('data.csv', 'w') as f:
        for i in a:
            f.write(i+'\n')




data_number = pd.read_csv(u'data.csv', encoding="gbk")
# data_number
plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
plt.rcParams['axes.unicode_minus']=False #用来正常显示负号
label = data_number.T.values
xtop = data_number.T.values
idx = np.arange(len(xtop))
fig = plt.figure(figsize=(12,12))
plt.barh(idx, xtop, color='b',alpha=0.6)
plt.yticks(idx+0.4,label)
plt.grid(axis='x')
plt.show()
# test = pd.DataFrame(columns=title,columns=number)
# test.to_csv('G:/test1.txt')
# print(number)
# for i in number:
#     a.append(int(i))
# print(max(tuple(a)))


